<?php
use wepay\join\demo\common\SignUtil;
use wepay\join\demo\common\DesUtils;
/**
 * Class ApiService
 */
class ApiService extends BaseService
{
    private static $self = NULL;

    static public function instance()
    {
        if (self::$self == NULL) {
            self::$self = new self;
        }

        return self::$self;
    }

    private $status_msgs        = NULL;
    private $mUser              = NULL;
    private $mUserThird			= NULL;
    private $mSupplier          = NULL;
    private $mProduct           = NULL;
    private $mLineQuery         = NULL;
    private $mInquiry           = NULL;
    private $mArticle           = NULL;
    private $mInformation       = NULL;
    private $mNotice            = NULL;
    private $mCircle            = NULL;
    private $mFeedback          = NULL;
    private $mCollection        = NULL;
    private $mLogisticsLine     = NULL;
    private $mCustomize         = NULL;
    private $mSupply            = NULL;
    private $mForest            = NULL;
    private $mProductCate       = NULL;
    private $mProductBrand      = NULL;
    private $mProductAttr       = NULL;
    private $mRefund            = NULL;
    private $mOrder             = NULL;
    private $mOrderShipping     = NULL;
    private $mCart              = NULL;
    private $mAddress           = NULL;
    private $mStorage           = NULL;
    private $mHarbour           = NULL;
    private $mHarbourNeed       = NULL;
    private $mAds               = Null;
    private $mDevice            = NULL;
    private $mRegion            = NULL;
    private $mProComment        = NULL;
    private $mForestNeed        = NULL;
    private $mStorageNeed       = NULL;
    private $mHelpCenter        = NULL;
    private $mCircleComment     = NULL;
    private $mCircleLike        = NULL;
    private $mVerify            = NULL;
    private $mQuote             = NULL;
    private $mOrderProduct      = NULL;
    private $mShipping          = NULL;
    private $mLogisticsStatus   = NULL;
    private $mPayMode           = NULL;
    private $mInvoice           = NULL;
    private $mMessage           = NULL;
    private $mSpec              = NULL;
    private $mLevel             = NULL;
    private $mArea              = NULL;
    private $mVideo             = NULL;
    private $mPlace             = NULL;
    private $mProductPic        = NULL;
    private $client             = NULL;
    private $mCircleReply       = NULL;
    private $mVersion           = NULL;
    private $mOpinion           = NULL;
    private $mPosUser           = NULL;


    public function __construct()
    {
        $this->status_msgs              = ProfessionErrorCodeEnum::$status_msgs;
        $this->mUser                    = new Involved_UserModel();
        $this->mUserThird				= new Involved_UserThirdModel();
        $this->mSupplier                = new Involved_SupplierModel();
        $this->mProduct                 = new Involved_ProductModel();
        $this->mLineQuery               = new Involved_LineQueryModel();
        $this->mInquiry                 = new Involved_InquiryModel();
        $this->mArticle                 = new Involved_ArticleModel();
        $this->mInformation             = new Involved_InformationModel();
        $this->mNotice                  = new Involved_NoticeModel();
        $this->mCircle                  = new Involved_CircleModel();
        $this->mFeedback                = new Involved_FeedbackModel();
        $this->mCollection              = new Involved_CollectionModel();
        $this->mLogisticsLine           = new Involved_LogisticsLineModel();
        $this->mCustomize               = new Involved_CustomizeModel();
        $this->mSupply                  = new Involved_SupplyModel();
        $this->mForest                  = new Involved_ForestModel();
        $this->mProductCate             = new Involved_ProductCateModel();
        $this->mProductBrand            = new Involved_ProductBrandModel();
        $this->mProductAttr             = new Involved_ProductAttrModel();
        $this->mRefund                  = new Involved_RefundModel();
        $this->mOrder                   = new Involved_OrderModel();
        $this->mOrderShipping           = new Involved_OrderShippingModel();
        $this->mCart                    = new Involved_CartModel();
        $this->mAddress                 = new Involved_AddressModel();
        $this->mArticle                 = new Involved_SupplierModel();
        $this->mStorage                 = new Involved_StorageModel();
        $this->mForest                  = new Involved_ForestModel();
        $this->mHarbour                 = new Involved_HarbourModel();
        $this->mHarbourNeed             = new Involved_HarbourNeedModel();
        $this->mAds                     = new Involved_AdsModel();
        $this->mDevice                  = new Involved_DeviceModel();
        $this->mRegion                  = new Involved_RegionModel();
        $this->mProComment              = new Involved_ProCommentModel();
        $this->mForestNeed              = new Involved_ForestNeedModel();
        $this->mStorageNeed             = new Involved_StorageNeedModel();
        $this->mVerify                  = new Involved_VerifyModel();
        $this->mHelpCenter              = new Involved_HelpCenterModel();
        $this->mCircleComment           = new Involved_CircleCommentModel();
        $this->mCircleLike              = new Involved_CircleLikeModel();
        $this->mQuote                   = new Involved_QuoteModel();
        $this->mOrderProduct            = new Involved_OrderProductModel();
        $this->mShipping                = new Involved_ShippingModel();
        $this->mLogisticsStatus         = new Involved_LogisticsStatusModel();
        $this->mPayMode                 = new Involved_PayModeModel();
        $this->mInvoice                 = new Involved_InvoiceModel();
        $this->mMessage                 = new Involved_MessageModel();
        $this->mSpec                    = new Involved_SpecModel();
        $this->mLevel                   = new Involved_LevelModel();
        $this->mArea                    = new Involved_ProducingAreaModel();
        $this->mVideo                   = new Involved_VideoModel();
        $this->mPlace                   = new Involved_PlaceModel();
        $this->mProductPic              = new Involved_ProductPicModel();
        $this->mCircleReply             = new Involved_CircleReplyModel();
        $this->mVersion                 = new Involved_VersionModel();
        $this->mOpinoin                 = new Involved_OpinionModel();
        $this->mPosUser                 = new Involved_PosUserModel();
    }

    /**
     * 参数验证
     * @param $obj
     * @param $arr
     * @author alice
     * @date 2016-1-13
     * @return bool
     * @return bool
     */
    public function  checkProperties($obj, $arr)
    {
        if (empty($arr)) return true;
        $obj = (array)$obj;

        foreach ($arr as $v) {
            if (is_null($obj[$v])) {
                return false;
            }
        }
        return true;
    }

    /**
     * 获取App信息
     * @author  fyl
     * @date    2016-5-19
     * @throws Exception
     */
    public function GetIndexApp(){
        $app_info = $this->mVersion->GetVersion();
        $app_info->token = QiniuUpload::instance()->generateToken();
        return $app_info;
    }


    /**
     * 获取首页数据
     * @param $paramObj
     * @author  fyl
     * @date    2016-5-04
     * @return array
     * @throws Exception
     */
    public function GetIndexData($paramObj)
    {
        #获取广告位列表
        $ads = $this->mAds->GetAdsList(AdEnum::AD_TYPE_INDEX_BANNER);

        #获取推荐产品列表
        $rec_products = $this->mProduct->GetSelfSupportList('index', $paramObj->page);
        foreach($rec_products as &$product){
           /* $product->level = $this->mLevel->GetLevelNameById($product->level);*/
           /* $product->spec = $this->mSpec->GetSpecNameById($product->spec);*/
            $product->created  = date('Y-m-d',$product->created);
            $product->company  = $this->mSupplier->ShowSupplierCompany($product->supplier_id)->company;
        }
        #返回数据
        return [
            'ads' => $ads,
            'rec_goods' => $rec_products
        ];
    }

    /**
     * 用户注册
     * @param $paramObj
     * @author fyl
     * @date 2016-5-04
     * @return mixed
     * @throws Exception
     */
    public function DeposeRegister($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile', 'password','phone']);
        if (!$check) {
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #手机号验证
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->mobile)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->phone)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #手机号是否已注册
        $mobile = $this->mUser->GetMobile($paramObj->mobile);
        if ($mobile !== 0) {
            throw new Exception("手机号已注册", ProfessionErrorCodeEnum::ERROR_ACCOUNT_EXIST);
        }

        #注册用户
        $aDate = [
            'mobile'        => $paramObj->mobile,
            'user_name'     => empty($paramObj->user_name)?'未填写':$paramObj->user_name,
            'password'      => md5($paramObj->password),
            'corporation'   => empty($paramObj->corporation)?'未填写':$paramObj->corporation,
            'phone'         => $paramObj->phone,
            'avatar'        => empty($paramObj->avatar)?'api.mutouw.com/resource/img/user.jpg':$paramObj->avatar
        ];
        $user_id = $this->mUser->insert($aDate);

        #是否注册成功
        if (!$user_id) {
            throw new Exception("注册失败", ProfessionErrorCodeEnum::ERROR_DB_UPDATE);
        }

        #返回用户信息
        $user_info = $this->mUser->GetUserInfo($user_id);
        return [
            'user_id'       =>   $user_id,
            'user_name'     =>   $user_info->user_name,
            'mobile'        =>   $user_info->mobile,
            'avatar'        =>   $user_info->avatar,
            'phone'        =>   $user_info->phone,
            'is_supplier'   =>   $user_info->is_supplier,
            'corporation'   =>   $user_info->corporation,
        ];
    }

    /**
     * 用户修改
     * @param $paramObj
     * @author fyl
     * @date 2016-5-04
     * @return mixed
     * @throws Exception
     */
    public function ModifyUserInfo($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        #参数验证
        $check = $this->checkProperties($paramObj, ['key', 'val']);
        if (!$check) {
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #手机号验证
        if($paramObj->key=='phone'){
            if (!preg_match('/^1[34578]\d{9}$/', $paramObj->val)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
            }
        }


        $aData = [
            "$paramObj->key" => $paramObj->val,
        ];

        return $this->mUser->update($aData,['user_id'=>$user_id]);

    }

    #手机号是否已注册
    public function Mobile($paramObj){
        $mobile = $this->mUser->GetMobile($paramObj->mobile);
        if ($mobile !== 0) {
            throw new Exception("手机号已注册", ProfessionErrorCodeEnum::ERROR_ACCOUNT_EXIST);
        }else{
            return new stdClass();
        }
    }

    /**
     * 用户登录
     * @param $paramObj
     * @author fyl
     * @date   2016-5-15
     * @return mixed
     * @throws Exception
     */
    public function DeposeLogin($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile', 'password']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        #用户登录
        $user_info = $this->mUser->login($paramObj->mobile, md5($paramObj->password));
        if (!$user_info) {
            throw new Exception("用户名或密码错误", ProfessionErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
        }

      /*  #记录用户
        $aData = [
            'mobile'         => $paramObj->mobile,
            'os_type'        => $paramObj->os_type,
            'model'          => $paramObj->model,
            'device_token'   => $paramObj->device_token,
            'created'        => time()
        ];

        $this->mDevice->insert($aData);*/
        session_put(UserEnum::USER_INFO_USER_ID, $user_info->user_id);
        session_put(UserEnum::USER_INFO_SESSION_KEY, $user_info);

        #是否供应商
      /*  $user_info->is_supplier    = $this->mVerify->checkSupplier($user_info->user_id, SupplierEnum::SUPPLIER_STATE_AFTER);*/
        $supplier  = $this->mSupplier->GetCommonInfo($user_info->user_id);
            if(!$supplier){
                $supplierInfo = new stdClass();
            }else{
                $supplierInfo = $supplier;
            }
        #商家信息
      /*  $supplierInfo = empty($user_info->is_supplier) ? new stdClass() :$this->mSupplier->GetSupplierInfo($user_info->user_id);*/

        #返回数据
        return [
            'base_info'     => $user_info,
            'supplier_info' => $supplierInfo,
        ];

    }
    
    /**
     * 第三方登陆
     * @param $paramObj
     * @author alice
     * @date 2016-1-13
     * @return mixed
     * @throws Exception
     */
    public function ThirdLogin($paramObj)
    {
    	#参数验证
    	$check = $this->checkProperties($paramObj, ['ch', 'ch_id', 'user_name', 'avatar', 'os_type', 'model', 'device_token']);
    	if (!$check) {
    		throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
    		ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
    	}
    
    	#验证第三方用户是否已经存在
    	$third_user = $this->mUserThird->getThirdUserByCh($paramObj->ch, $paramObj->ch_id);
    	#存在则 更新用户头像、用户昵称，拿出相应的用户信息

    	if ($third_user) {
    		$user_id 		= $third_user->fk_user_id;
            $update_data    = ['avatar' => $paramObj->avatar, 'user_name' =>$paramObj->user_name];
    		$this->mUser->updateByUserId( $user_id, $update_data );
    	} else {
    		#不存在则 注册用户，保存用户信息
    		#注册用户
    		$insert_user = array(
    			'user_name'     => $paramObj->user_name,
    			'avatar'		=> $paramObj->avatar,
    			'created'   	=> time(),
    		);
    		$user_id = $this->mUser->insert($insert_user);
    		#是否注册成功
    		if (!$user_id) {
    			throw new Exception("注册失败", ProfessionErrorCodeEnum::ERROR_DB_UPDATE);
    		}
    		#保存第三方用户信息
    		$insert_user_third	= array(
    			'fk_user_id'	=> $user_id,
    			'ch'			=> $paramObj->ch,
    			'ch_id'			=> $paramObj->ch_id,
    			'created'		=> time(),
    		);
    		$third_user_id	= $this->mUserThird->insert($insert_user_third);
    		#是否保存成功
    		if (!$third_user_id) {
    			throw new Exception("保存第三方用户信息失败", ProfessionErrorCodeEnum::ERROR_DB_UPDATE);
    		}
    	}	
    
    	#用户信息
    	$user_info = $this->mUser->GetUserInfo($user_id);
    	
    	#记录数据
    	$device = array(
    		'mobile'         => '',
    		'os_type'        => $paramObj->os_type,
    		'model'          => $paramObj->model,
    		'device_token'   => $paramObj->device_token,
    		'created'        => time()
    	);
    	
    	$this->mDevice->insert($device);
    	session_put(UserEnum::USER_INFO_USER_ID, $user_id);
    	session_put(UserEnum::USER_INFO_SESSION_KEY, $user_info);

        #是否供应商
        $user_info->is_supplier    = $this->mVerify->checkSupplier($user_id, SupplierEnum::SUPPLIER_STATE_AFTER);

        #商家信息
        $supplierInfo = empty($user_info->is_supplier) ? new stdClass() :$this->mSupplier->GetSupplierInfo($user_id);

        #返回数据
        $data = [
             'base_info'        =>  $user_info,
             'supplier_info'    =>  $supplierInfo,
        ];

        return $data;
    }

    /**
     * 用户信息
     * @return array
     * @throws Exception
     * @author buluota
     * @data   2016-1-20
     */
    public function GetUserInfo()
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        #基本信息
        $baseInfo = $this->mUser->getUserInfo($user_id);
        if(!$baseInfo){
            $this->Logout();
            throw new Exception('用户不存在！', ErrorCodeEnum::STATUS_ERROR_NOT_IN);
        }

        #商家信息
        $supplier  = $this->mSupplier->GetCommonInfo($baseInfo->user_id);
        if(!$supplier){
            $supplierInfo = new stdClass();
        }else{
            $supplierInfo = $supplier;
        }

        #返回数据
        $data = [
            'base_info' => $baseInfo,
            'supplier_info' => $supplierInfo,
        ];

        return $data;
    }

    /**
     * 用户注销
     * @return bool
     * @throws Exception
     * @author fyl
     * @data   2016-5-10
     */
    public function Logout()
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_info = session_get(UserEnum::USER_INFO_SESSION_KEY);

        #清空设备信息
        $result   = array('status'=>1);

        #清空SESSION
        Session::flush();

        return $result;
    }

    /**
     * 完善信息
     * @param $paramObj
     * @return bool
     * @throws Exception
     * @author fyl
     * @data   2016-5-7
     */
    public function ModifyCommonDetail($paramObj)
    {
        #验证登陆
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['company', 'phone']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        #保存数据
        $aData      =   [
            'company'       => $paramObj->company,
            'phone'         => $paramObj->phone,
            'supplier_id'   => $user_id,
        ];
        //非空字段
        $aData['supplier_name']   = !empty($paramObj->supplier_name)?$paramObj->supplier_name:'未填写';
        $aData['address']         =  !empty($paramObj->address)?$paramObj->address:'未填写';
        $aData['address_all']     =  !empty($paramObj->address_all)?$paramObj->address_all:'未填写';
        $aData['phone']           = !empty($paramObj->phone)?$paramObj->phone:'未填写';
        $aData['operate_license'] = !empty($paramObj->operate_license)?$paramObj->operate_license:'未填写';
        $aData['show_img1']       =  !empty($paramObj->show_img1)?$paramObj->show_img1:'未填写';
        $aData['show_img2']       =  !empty($paramObj->show_img2)?$paramObj->show_img2:'未填写';
        $aData['show_img3']       =  !empty($paramObj->show_img3)?$paramObj->show_img3:'未填写';

        #返回数据

        if($paramObj->supplier_id){
            $this->mSupplier->update($aData,['supplier_id'=>$user_id]);
        }else{
            if ($this->mSupplier->ShowSupplierInfo($user_id))
                throw new Exception('您已经是商家', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_SU);
            $aData['created']         =  time();
            $this->mSupplier->insert($aData);
            $this->mUser->update(['is_supplier'=>1],['user_id'=>$user_id]);
        }

        #获取完善信息
        return $this->mSupplier->GetCommonInfo($user_id);
    }

    /**
     * 获取完善信息
     * @return mixed
     * @throws Exception
     * @author buluota
     * @data   2016-1-20
     */
    public function GetCommonDetail()
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #获取完善信息
        return $this->mSupplier->GetCommonInfo($user_id);
    }

    /**
     * 资质审核
     * @param $paramObj
     * @return bool
     * @throws Exception
     * @author buluota
     * @data   2016-1-20
     */
    public function ModifyCertifyInfo($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['market', 'bank_account', 'bank_number']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #保存数据
        $aData = [
            'market'            =>   $paramObj->market,
            'bank_account'      =>   $paramObj->bank_account,
            'bank_number'       =>   $paramObj->bank_number,
            'storage'           =>   $paramObj->storage
        ];

        $aData['id_card']           =   $paramObj->id_card;
        $aData['operate_license']   =   $paramObj->operate_license;
        $aData['tax_license']       =   $paramObj->tax_license;

        #提交审核&保存数据
        $aVerify = [
            'supplier_id'   =>  $user_id,
            'state'         =>  SupplierEnum::SUPPLIER_STATE_DOING,
            'created'       =>  time()
        ];
        $res_verify     =   $this->mVerify->insert($aVerify);
        if(!$res_verify)
            throw new Exception('资质申请失败！', ErrorCodeEnum::STATUS_SUCCESS_DO_ERROR_DB);

        $res_supplier   =   $this->mSupplier->AddVerify($aData, $user_id);
        if(!$res_supplier)
            throw new Exception('更新资质申请失败！', ErrorCodeEnum::STATUS_SUCCESS_DO_ERROR_DB);

        return $this->mSupplier->GetCertifyInfo($user_id);
    }

    /**
     * 文件上传
     * @param $file
     * @param $type
     * @return string
     * @throws Exception
     */
    public function uploadImg($file, $type)
    {
        $clientName = $file->getClientOriginalName();
        $extension  = $file->getClientOriginalExtension();
        $newName    = md5(date('ymdhis').$clientName).".".$extension;
        $file -> move(public_path().'/resource/'.$type,$newName);

        if($file->getError()){
            throw new Exception('文件上传失败！', ProfessionErrorCodeEnum::ERROR_UPLOAD_FILE_FAILED);
        }

        return '/resource/'.$type.'/'.$newName;
    }


    /**
     * 获取审核信息
     * @return mixed
     * @throws Exception
     * @author buluota
     * @data   2016-1-20
     */
    public function GetCertifyDetail()
    {
        #登录验证
        $userInfo   =   Session::get(UserEnum::CLIENT_INFO_SESSION_KEY);
        if (!$userInfo)
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);

        #获取审核信息
        return $this->mSupplier->GetCertifyInfo($userInfo->user_id);
    }

    /**
     * 密码修改
     * @param $paramObj
     * @return bool
     * @throws Exception
     * @author fyl
     * @data   2016-5-13
     */
    public function ModifyPassword($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['origin_pass', 'new_pass', 'confirm_pass']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #验证原密码
        $check     =    $this->mUser->CheckPassword($user_id, md5($paramObj->origin_pass));
        if(!$check)
            throw new Exception('密码输入错误', ProfessionErrorCodeEnum::ERROR_PASSWORD_WRONG);

        #新密码一致性
        if($paramObj->new_pass !== $paramObj->confirm_pass)
            throw new Exception('新密码输入不一致', ProfessionErrorCodeEnum::ERROR_PASSWORD_DIFFERENT);

        #保存数据
        $arr = new stdClass();
        $arr -> status = $this->mUser->ModifyPassword($paramObj->new_pass, $user_id);
        return $arr;
    }

    /**
     * 重置密码
     * @param $paramObj
     * @return bool
     * @throws Exception
     * @author fyl
     * @data   2016-5-13
     */
    public function ResetPassword($paramObj)
    {

        #参数验证
        $check      =   $this->checkProperties($paramObj, [ 'new_pass','mobile']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        #保存数据
        $arr = new stdClass();
        $arr->status = $this->mUser->ResetPassword($paramObj->new_pass, $paramObj->mobile);

        return $arr;
    }

    /**
     * 自营商品列表
     * @param $paramObj
     * @return mixed
     * @throws Exception
     * @author buluota
     * @data   2016-1-20
     */
    public function GetSelfSupportProduct($paramObj)
    {
        #参数验证
        $check      =   $this->checkProperties($paramObj, ['service_type','page']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #获取自营商品列表
        return $this->mProduct->GetSelfSupportProduct($paramObj->service_type,$paramObj->page);
    }

    /**
     * 商城商品列表
     * @param $paramObj
     * @return mixed
     * @throws Exception
     */
    public function GetShopProduct($paramObj)
    {
       $product_list =  $this->mProduct->GetApiProductList($paramObj);
      /* foreach($product_list as &$product){
           $product->level = property_exists($product,'level') ? $this->mLevel->GetLevelNameById($product->level) : "未填";
           $product->spec = property_exists($product,'spec') ? $this->mSpec->GetSpecNameById($product->spec) : "未填";
       }*/
        return $product_list;
    }

    /**
     * 商城产品筛选
     * @param $paramObj
     * @return array
     * @throws Exception
     */
    public function GetShopProductCondition($paramObj)
    {
        #参数验证
        $check      =   $this->checkProperties($paramObj, ['condition_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #逻辑处理
        switch ($paramObj->condition_type) {
            case 'category':
                $data = $this->mProductCate->GetListByParentId($paramObj->condition_id, ['cate_id','cate_name']);
                break;
            case 'service_type':
                $data = $this->mProductCate->GetListByParentId($paramObj->condition_id);
                break;
            case 'is_self_support':
                //自营
                $data = ProductEnum::$support;
                break;
            case 'classes':
                //品类
                //todo
                $data = [];
                break;
            case 'quality':
                //材质
                //todo
                $data = [];
                break;
            case 'spec':
                //规格
                //todo
                $data = [];
                break;
            case 'level':
                //等级
                $data = ProductEnum::$product_level;
                break;
            case 'origin':
                //产地
                //todo
                break;
            case 'storage':
                //仓储地
                //todo
                break;
            case 'brand':
                //品牌
                $data = $this->mProductBrand->GetList(array('brand_id','brand_name'));
                break;
            default :
                throw new Exception('参数 condition_type 值不正确', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS);
        }

        return $data;

    }

    /**
     * 产品上下架列表
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-2-16
     */
    public function GetManageProduct($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['op']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $product_list = $this->mProduct->GetManageProduct($user_id, $paramObj->op,$paramObj->page,$paramObj->status);
        $products = new stdClass();
        foreach($product_list as $key => $product)
        {

            /*$brand = $this->mProductBrand->GetProductBrandById($product->brand_id);*/
            /*$product->level = property_exists($product,'level') ? $this->mLevel->GetLevelNameById($product->level) : "未填";*/
         /*   $product->spec = property_exists($product,'spec') ? $this->mSpec->GetSpecNameById($product->spec) : "未填";*/
            $products->product_list[] = [
                'product_id'        =>  $product->product_id,
                'product_name'      =>  $product->product_name,
                'spec'              =>  $product->spec,
                'price'             =>  $product->price,
                'product_img'       =>  $product->product_img,
                'created'           =>  date('Y-m-d',$product->created),
                'is_up'             =>  $product->is_up,
                'stock'             =>  $product->stock,
            ];

        }

        return $products;
    }

    /**
     * 商品上架下架
     * @param $paramObj
     * @return bool
     * @throws Exception
     * @author fyl
     * @date 2016-5-10
     */
    public function ManageProduct($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['product_id', 'op']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $paramObj->op   =   ($paramObj->op == 'up') ? 1 :  0;

        #逻辑处理
        $aWhere  =   [
            'supplier_id'   =>  $user_id,
            'product_id'    =>  $paramObj->product_id
        ];
        $result =    $this->mProduct->update(['is_up'=> $paramObj->op],$aWhere);
        if(!$result)
            throw new Exception('数据库操作失败!', ProfessionErrorCodeEnum::STATUS_ERROR);

        return $result;
    }

    /**
     * 林场列表
     * @return array
     * @author alice
     * @date 2016-1-23
     */
    public function GetForestList()
    {
        return $this->mForest->GetForestList();
    }

    /**
     * 林场详情
     * @param $paramObj
     * @return mixed
     * @throws Exception
     * @author alice
     * @date 2016-1-23
     */
    public function ForestDetail($paramObj)
    {
        #参数验证
        $check      =   $this->checkProperties($paramObj, ['forest_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        //$video_url = $this->VideoPlayUrl('forest_id',$paramObj->forest_id);
        $data = $this->mForest->GetForestById($paramObj->forest_id);

        return $data;
    }

    /**
     * 林场直供需求
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author alice
     * @date 2016-1-24
     */
    public function ForestNeed($paramObj)
    {
//        #登录验证
//        $userInfo   =   Session::get(UserEnum::CLIENT_INFO_SESSION_KEY);
//        if (!$userInfo)
//            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);

        $params['forest_id']        =   $paramObj->forest_id;
        $params['product_name']     =   $paramObj->product_name;
        $params['number']           =   $paramObj->number;
        $params['spec']             =   $paramObj->spec;
        $params['contact']          =   $paramObj->contact;
        $params['mobile']           =   $paramObj->mobile;
        $params['supplier_name']    =   $paramObj->supplier_name;

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['forest_id','product_name','number','spec','contact','mobile','supplier_name']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $this->mForestNeed->insert($params);
    }

    /**
     * 线路查询
     * @param $paramObj
     * @author alice
     * @date 2016-1-21
     * @return mixed
     * @throws Exception
     */
    public function QueryLine($paramObj)
    {
        return $this->mLogisticsLine->LogisticsLine($paramObj->departure, $paramObj->destination, $paramObj->spec_time);
    }

    /**
     * 仓储列表
     * @param $paramObj
     * @return bool
     * @throws Exception
     * @author alice
     * @date 2016-1-23
     */
    public function GetStorageList($paramObj)
    {
        #参数验证
        $check      =   $this->checkProperties($paramObj, ['type']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $data       = new stdClass();
        $storage_list = $this->mStorage->GetStorageList($paramObj->type);
        foreach($storage_list as $storage){
            #取出单条仓储基地
            $row = [
                'storage_id'        =>  $storage->storage_id,
                'storage_name'      =>  $storage->storage_name,
                'storage_address'   =>  $storage->storage_address,
                'rank'              =>  $storage->rank,
                'show_pic1'         =>  $storage->show_pic1,
            ];

            #生成不同region
            if(!isset($data->storage_list[$storage->region_id])){
                $data->storage_list[$storage->region_id] = [
                    'region_id'     =>  $storage->region_id,
                    'region_name'   =>  $storage->region_name,
                    'storages'      =>  []
                ];
            }

            #仓储基地push到region中
            $data->storage_list[$storage->region_id]['storages'][] = $row;
        }
         shuffle($data->storage_list);
         return $data;
    }

    /**
     * 仓储详情
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-1-23
     */
    public function StorageDetail($paramObj)
    {
        #参数验证
        $check      =   $this->checkProperties($paramObj, ['storage_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        return $this->mStorage->GetStorageDetail($paramObj->storage_id);
    }

    /**
     * 仓储需求
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author alice
     * @date 2016-1-24
     */
    public function StorageNeed($paramObj)
    {
//        $userInfo   =   Session::get(UserEnum::CLIENT_INFO_SESSION_KEY);
//        if (!$userInfo)
//            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);

        $params['storage_id']       =   $paramObj->storage_id;
        $params['product_name']     =   $paramObj->product_name;
        $params['number']           =   $paramObj->number;
        $params['spec']             =   $paramObj->spec;
        $params['start_time']       =   $paramObj->start_time;
        $params['end_time']         =   $paramObj->end_time;
        $params['introduce']        =   $paramObj->introduce;
        $params['contact']          =   $paramObj->contact;
        $params['mobile']           =   $paramObj->mobile;

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['storage_id','product_name','number','spec',
                                                            'start_time','end_time','contact','mobile']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $this->mStorageNeed->insert($params);

    }

    /**
     * 港口列表
     * @return mixed
     * @author alice
     * @date 2016-1-23
     */
    public function GetHarbourList()
    {
        return $this->mHarbour->GetHarbourList();
    }

    /**
     * 港口详情
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-1-23
     */
    public function HarbourDetail($paramObj)
    {
        #参数验证
        $check      =   $this->checkProperties($paramObj, ['harbour_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #点击量
        DB::table('harbour')->where("harbour_id",$paramObj->harbour_id)->increment('visit',1);

        return $this->mHarbour->GetHarbourDetail($paramObj->harbour_id);

    }

    /**
     * 港口需求
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author alice
     * @date 2016-1-24
     */
    public function HarbourNeed($paramObj)
    {
//        $userInfo   =   Session::get(UserEnum::CLIENT_INFO_SESSION_KEY);
//        if (!$userInfo)
//            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);

        $params['harbour_id']       =   $paramObj->harbour_id;
        $params['product_name']     =   $paramObj->product_name;
        $params['number']           =   $paramObj->number;
        $params['spec']             =   $paramObj->spec;
        $params['expire_time']      =   $paramObj->expire_time;
        $params['certificate']      =   $paramObj->certificate;
        $params['introduce']        =   $paramObj->introduce;
        $params['contact']          =   $paramObj->contact;
        $params['mobile']           =   $paramObj->mobile;

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['harbour_id','product_name','number','expire_time',
                                                            'certificate','contact','mobile']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $this->mHarbourNeed->insert($params);
    }

    /**
     * 获取产品详情
     * @param $paramObj
     * @return array
     * @author alice
     * @date 2016-1-26
     */
    public function GetProductDetail($paramObj)
    {
        #产品信息

        $product = $this->mProduct->GetProductDetail($paramObj->product_id);
        /*$pic = $this->mProductPic->GetPic($paramObj->product_id);*/
        #产品评价
      /*  $comment  = $this->mProComment->GetCommentList($paramObj->product_id);*/
        #判断产品是否收藏
      /*  $is_collection = $this->mCollection->GetCollectionById($paramObj->product_id);*/
        $arr = array();
        if($product->show_img1){
           $arr[] = $product->show_img1;
        }
        if($product->show_img2){
            $arr[] = $product->show_img2;
        }
        if($product->show_img3){
            $arr[] = $product->show_img3;
        }
        return [
                'supplier_id'       =>  $product->supplier_id,
                'product_name'      =>  $product->product_name,
                'company'           =>  $product->company,
                'product_sn'        =>  $product->product_sn,
                'price'             =>  $product->price,
                'spec'              =>  $product->spec,
                'storage'           =>  $product->storage,
                'place'             =>  $product->place,
               /* 'level'             =>  $this->mLevel->GetLevelNameById($product->level),*/
                'stock'             =>  $product->stock,
                'unit'              =>  $product->unit,
                'start_num'         =>  $product->start_num,
                'brief'             =>  /*empty($product->brief) ? '自营产品' :*/ $product->brief,
                'cate_name'         =>  $product->cate_name,
                'classes'           =>  $product->classes,
                'phone'             =>  $product->phone,
                'description'       =>  $product->description,
                'product_pic'       =>  $arr
              /*  'comment'           =>  $comment,
                'collection'        =>  $is_collection,*/
            ];


    }

    /**
     * 加入 / 取消收藏
     * @param $paramObj
     * @return int
     * @throws Exception
     */
    public function CollectProduct($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['product_id','op']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #验证收藏
        $count = $this->mCollection->CheckCollection($user_id, $paramObj->product_id);

        if(!$count && $paramObj->op == 1){
            $aData = [
                'product_id'    =>  $paramObj->product_id,
                'user_id'       =>  $user_id,
                'created'       =>  time()
            ];
            return   $this->mCollection->insert($aData);
        }
        else if($count && $paramObj->op == 0)
        {
            $aWhere =    [
                'product_id'    => $paramObj->product_id,
                'user_id'       => $user_id
            ];
            return $this->mCollection->delete($aWhere);
        }else{}
    }

    /**
     * 我的收藏
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-2-16
     */
    public function GetCollectList($paramObj)
    {
        #验证登陆
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #收藏列表
        $collect_list = $this->mCollection->GetCollectionList($paramObj->page,$user_id);

        return [
            'collect_list'  =>  $collect_list,
        ];
    }

    /**
     * 添加购物车
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author
     */
    public function AddCart($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['product_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        $product = $this->mProduct->GetProductById($paramObj->product_id);
        $cart_product = $this->mCart->GetProductId($paramObj->product_id, $user_id);
        #检查库存
        if($cart_product){
            if($product->stock <= ($cart_product->number))
                throw new Exception('库存不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
            $aWhere = ['product_id' => $paramObj->product_id, 'user_id' => $user_id];
            $aData = new stdClass();
            $aData->status = DB::table('cart')->where($aWhere)->increment('number',1);
            return $aData;
        }else{
            #保存数据
            if($product->stock < 1)
                throw new Exception('库存不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
            $aData = [
                'user_id'       =>  $user_id,
                'product_id'    =>  $paramObj->product_id,
                'product_name'  =>  empty($product->product_name)?'':$product->product_name,
                'product_sn'    =>  empty($product->product_sn)?'':$product->product_sn,
                'supplier_id'   =>  empty($product->supplier_id)?'':$product->supplier_id,
               'supplier_name'  =>  empty($product->supplier_name)?'':$product->supplier_name,
                'product_img'   =>  empty($product->product_img)?'':$product->product_img,
                'spec_name'     =>  empty($product->spec_name)?'':$product->spec_name,
                'price'         =>  empty($product->price)?'':$product->price,
                'amount'        =>  empty($product->amount)?'':$product->amount,
                'quality_name'  =>  empty($product->quality_name)?'':$product->quality_name,
                'number'        =>  1,
                'created'       =>  time()
            ];

            $result = $this->mCart->insert($aData);
            if(!$result)
                throw new Exception('添加购物车失败', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

            return $result;

        }


    }

    /**
     * 获取购物车列表
     * @return stdClass
     * @throws Exception
     */
    public function CartList($paramObj)
    {
        #验证登陆
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #购物车产品列表
        $cart_list =  $this->mCart->GetUserCartList($user_id,$paramObj);
        $row = new stdClass();
        foreach($cart_list as $product){
            $row->cart_list[] = [
                'product_id'        =>  $product->product_id,
                'cart_id'           =>  $product->cart_id,
                'product_name'      =>  $product->product_name,
                'product_thumb'     =>  $product->product_img,
                'spec'              =>  $product->spec_name,
                'stock'             =>  $product->stock,
               /* 'quality'           =>  $product->quality_name,*/
              /*  'level'             =>  $product->level_name,*/
                'price'             =>  $product->price,
                'number'            =>  $product->number,
                'amount'            =>  number_format($product->price * $product->number,2),
            ];
            }
        return $row;
    }

    /**
     * 更新购物车
     * @param $paramObj
     * @return bool
     * @throws Exception
     */
    public function UpdateCart($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['product_id','product_num']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $product    =   $this->mProduct->GetProductDetail($paramObj->product_id);
        if($paramObj->product_num > $product->stock)
            throw new Exception('库存不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        $amount     =   number_format($product->price * $paramObj->product_num,2);
        #保存数据

        return $this->mCart->update(['number' => $paramObj->product_num,'amount'=> $amount],
            [
                'user_id'   =>  $user_id,
                'product_id' => $paramObj->product_id
            ]);

    }

    /**
     * 购物车删除产品
     * @param $paramObj
     * @return int
     * @throws Exception
     */
    public function DeleteCart($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['cart_id']);
        if (!$check) {
            throw new Exception('参数不足!',ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #删除购物车产品
        $result = new stdClass();
        $result->status =  $this->mCart->DeleteCart($user_id,$paramObj->cart_id);
        if(!$result->status){
            throw new Exception("数据库操作失败!", ErrorCodeEnum::STATUS_ERROR);
        }

        return $result;
    }

    /**
     * 修改地址
     * @param $paramObj
     * @return bool|int
     * @throws Exception
     */
    public function ModifyAddress($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
       #参数验证
        $check      =   $this->checkProperties($paramObj, ['address_all','consignee','mobile','address']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        $aData = [
            'is_default'     => UserEnum::CLIENT_USER_DEFAULT_ADDRESS,
            'user_id'        => $user_id,
            'consignee'      => $paramObj->consignee,
            'address'        => $paramObj->address,
            'mobile'         => $paramObj->mobile,
            'address_all'    => $paramObj->address_all,
        ];
        #将其他收货地址设置为非默认
        if($paramObj->address_id){
            $this->mAddress->update(['is_default' => UserEnum::CLIENT_USER_OTHER_ADDRESS],['user_id'    => $user_id]);
            $arr = new stdClass();
            $arr->address_id = $this->mAddress->update($aData,['address_id' => $paramObj->address_id]);
            return  $arr;
        }else{
            $this->mAddress->update(['is_default' => UserEnum::CLIENT_USER_OTHER_ADDRESS],['user_id'    => $user_id]);
            $arr = new stdClass();
            $arr->address_id = $this->mAddress->insert($aData);
            return $arr;
        }
    }

    /**
     * 修改默认地址
     * @param $paramObj
     * @return bool|int
     * @throws Exception
     */
    public function ModifyIsDefault($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        $check      =   $this->checkProperties($paramObj, ['address_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        #将其他收货地址设置为非默认
            $this->mAddress->update(['is_default' => UserEnum::CLIENT_USER_OTHER_ADDRESS],['user_id'    => $user_id]);
        return  $this->mAddress->update(['is_default' => UserEnum::CLIENT_USER_DEFAULT_ADDRESS],['address_id' => $paramObj->address_id]);
    }

    /**
     * 删除收货地址
     * @param $paramObj
     * @return bool|int
     * @throws Exception
     */
    public function DeleteAddress($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['address_id','is_default']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #将其他收货地址设置为非默认
        if($paramObj->is_default == 1){
            $result = new stdClass();
            $result->status = $this->mAddress->update(['status'=>0,'is_default'=>0],['address_id'=>$paramObj->address_id]);
            $address = $this->mAddress->GetOneAddress($user_id);
            if($address){
                $this->mAddress->update(['is_default' => UserEnum::CLIENT_USER_DEFAULT_ADDRESS],['address_id' => $address->address_id]);
            }
        }else{
            $result = new stdClass();
            $result->status = $this->mAddress->DeleteAddress($paramObj);
        }

        if (!$result->status)
            throw new Exception("数据库操作失败!", ErrorCodeEnum::STATUS_ERROR);

        return $result;
    }

    /**
     * 收货地址列表
     * @return mixed
     * @throws Exception
     */
    public function GetAddressList()
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #地址列表
        $address_list = $this->mAddress->GetAddressList($user_id);

        return [
            'address_list'  =>  $address_list,
        ];
    }

    /**
     * 木业资讯列表
     * @param $paramObj
     * @return array
     * @throws Exception
     */
    public function GetInformationList($paramObj)
    {
        $list = $this->mInformation->GetInformationList($paramObj);

        $data = [];
        foreach ($list as $v) {
            $row = [
                'zx_id'      => $v->zx_id,
                'title'      => $v->title,
                'content'    => strip_tags($v->content),
                'cate'       => $v->cate,
                'thumb_img'  => [],
                'link'       => "http://api.mutouw.com/Api/information_detail?news_id=$v->zx_id",
            ];
            if(!empty($v->thumb_img1)) array_push($row['thumb_img'], $v->thumb_img1);
            if(!empty($v->thumb_img2)) array_push($row['thumb_img'], $v->thumb_img2);
            if(!empty($v->thumb_img3)) array_push($row['thumb_img'], $v->thumb_img3);
            array_push($data,$row);
        }
        return $data;
    }

    /**
     * 木业资讯详情
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-2-16
     */
    public function GetInformationDetail($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['news_id']);
        if (!$check) {
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #资讯详情
        $result = $this->mInformation->GetInformationDetail($paramObj->news_id);
        if(!$result){
            throw new Exception("获取木业资讯失败!", ErrorCodeEnum::STATUS_ERROR);
        }

        return $result;
    }

    /**
     * 获取帮助中心
     * @return stdClass
     */
    public function HelpCenter()
    {
        $data = new stdClass();

        #获取帮助文章列表
        $data->base_help = $this->mHelpCenter->ShowHelpList();

        #获取热门帮助列表
        $data->hot_help = $this->mHelpCenter->GetHotHelpList();

        return $data;
    }

    /**
     * 获取帮助文章
     * @param $paramObj
     * @return array
     * @throws Exception
     */
    public function HelpArticle($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['help_id']);
        if (!$check) {
            throw new Exception('参数不足!',ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #获取文章详情
        $data = $this->mHelpCenter->GetHelpInfo($paramObj->help_id);

        return [
            'help_id'   =>  $data->help_id,
            'title'     =>  $data->title,
            'content'   =>  $data->content
        ];
    }

    /**
     * 关于木投
     * @return array
     */
    public function About()
    {
        #获取关于木投
        $data = $this->mHelpCenter->GetAboutInfo();

        return [
            'article_id'    =>  $data->help_id,
            'title'         =>  $data->title,
            'content'       =>  $data->content
        ];
    }

   /**
     * 商家入驻
     * @param $paramObj
     * @author fyl
     * @date 2016-5-06
     * @return mixed
     * @throws Exception
     */
    /*  public function AddSupplier($paramObj)
     {
         #参数验证
         $check = $this->checkProperties($paramObj, ['user_id','company', 'supplier_name','phone']);
         if (!$check) {
             throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                 ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
         }

         #手机号验证
         if (!preg_match('/^1[34578]\d{9}$/', $paramObj->phone)) {
             throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
         }

         #注册用户
         $aDate = [
             'supplier_id'          => $paramObj->supplier_id,
             'supplier_name'        => $paramObj->supplier_name,
             'company'              => $paramObj->company,
             'address'              => $paramObj->address,
             'address_all'          => $paramObj->address_all,
             'phone'                => $paramObj->phone,
             'operate_license'      => $paramObj->operate_license,
             'show_img1'            => $paramObj->show_img1,
             'show_img2'            => $paramObj->show_img2,
             'show_img3'            => $paramObj->show_img3,
             'created'              => time()
         ];
         $supplier_id = $this->mSupplier->insert($aDate);

         #是否注册成功
         if (!$supplier_id) {
             throw new Exception("注册失败", ProfessionErrorCodeEnum::ERROR_DB_UPDATE);
         }

         #返回用户信息
         $supplier_info = $this->mUser->GetUserInfo($supplier_id);
         return [
             'supplier_id'       =>   $supplier_id,
             'supplier_name'     =>   $supplier_info->supplier_name,
             'phone'             =>   $user_info->phone,
         ];
     }*/



    /**
     * 商家详情
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-1-26
     */
    public function GetSupplierDetail($paramObj)
  {
    #参数验证
    $check = $this->checkProperties($paramObj, ['supplier_id']);
    if (!$check) {
        throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);}

    #商家详情
    $supplier = $this->mSupplier->GetSupplierDetail($paramObj->supplier_id);

    #产品列表
    $products = $this->mProduct->GetSupplierProductList($paramObj->supplier_id, $paramObj->page);

      $data = [
          'img'                    => [],
          'supplier_id'            => $supplier->supplier_id,
          'supplier_name'          => $supplier->supplier_name,
          'brand_name'             => $supplier->brand,
          'scale'                  => $supplier->scale,
          'storage'                => $supplier->storage,
          'business_scope'         => $supplier->business_scope,
          'market'                 => $supplier->market,
          'product_list'           => $products,
      ];
      if(!empty($supplier->show_img1)) array_push($data['img'],$supplier->show_img1);
      if(!empty($supplier->show_img2)) array_push($data['img'],$supplier->show_img2);
      if(!empty($supplier->show_img3)) array_push($data['img'],$supplier->show_img3);

        return $data;

  }

    /**
     * 获取木业圈动态
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-2-15
     */
    public function GetCircleList($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['is_self']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #登录验证
        if ($paramObj->is_self == 1 && !session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #获取木业圈信息
        $circles   = $this->mCircle->getCircles($user_id, $paramObj->page,$paramObj->is_self);

        $info['circle_list'] = [];
        foreach($circles as $k => $c){
            #点赞
            $like = $this->mCircleLike->GetLikeList($c->circle_id);

            #评论
            $comment = $this->mCircleComment->GetCircleList($c->circle_id);

            #是否点赞
            $is_like = $this->mCircleLike->GetLikeNum($user_id,$c->circle_id);

            #判断是否为空
            $show_img = [];
            for($i=1;$i<=9;$i++)
            {
                $img = 'show_img'.$i;
                if(!empty($c->$img)) {
                    $show_img[] = $c->$img;
                }
            }

            $info['circle_list'][] = [
                'circle_id' =>  $c->circle_id,
                'user_id'   =>  $c->user_id,
                'user_name' =>  $c->user_name,
                'avatar'    =>  empty($c->avatar) ? 'http://media.mutouw.com/profile.png' : $c->avatar,
                'content'   =>  preg_replace_callback('/@E(.{6}==)/', function($r) {return base64_decode($r[1]);}, $c->content),
                'created'   =>  date('Y-m-d H:i:s', $c->created),
                'img'       =>  $show_img,
                'like'     =>   $like,
                'comment'  =>   $comment,
                'is_like'  =>   $is_like
            ];
        }

        return $info;
    }

    /**
     * 木业圈发布消息
     * @param $paramObj
     * @return string
     * @throws Exception
     */
    public function PublishCircle($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_info = session_get(UserEnum::USER_INFO_SESSION_KEY);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['content']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        #保存数据
        $aData = [
            'supplier_id'       =>  $user_info->user_id,
            'supplier_name'     =>  $user_info->user_name,
            'show_img1'         =>  $paramObj->show_img1,
            'show_img2'         =>  $paramObj->show_img2,
            'show_img3'         =>  $paramObj->show_img3,
            'show_img4'         =>  $paramObj->show_img4,
            'show_img5'         =>  $paramObj->show_img5,
            'show_img6'         =>  $paramObj->show_img6,
            'show_img7'         =>  $paramObj->show_img7,
            'show_img8'         =>  $paramObj->show_img8,
            'show_img9'         =>  $paramObj->show_img9, //处理表情字符
            'content'           =>  preg_replace_callback('/[\xf0-\xf7].{3}/', function($r) { return '@E' . base64_encode($r[0]);}, $paramObj->content),
            'created'           =>  time(),
        ];

        return  $this->mCircle->insert($aData);
    }

    /**
     * 木业圈评论
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author alice
     * @date 2016-1-26
     */
    public function AddCircleComment($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['circle_id','content']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #获取用户
        $user_info = $this->mUser->getUserInfo($user_id);

        #保存数据
        $aData = [
            'user_id'       =>  $user_id,
            'content'       =>  preg_replace_callback('/[\xf0-\xf7].{3}/', function($r) { return '@E' . base64_encode($r[0]);}, $paramObj->content),
            'circle_id'     =>  $paramObj->circle_id,
            'user_name'     =>  $user_info->user_name,
        ];

        $result = $this->mCircleComment->insert($aData);

        if (!$result) {
            throw new Exception("操作失败!", ErrorCodeEnum::STATUS_ERROR);
        }

        return $result;

    }

    /**
     * 获取上传图片token
     * @return string
     */
    public function GetToken()
    {
        return QiniuUtil::instance()->getToken();
    }

    /**
     * 木业圈  点赞/取消
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author alice
     * @date 2016-1-26
     */
    public function AddCircleLike($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['is_like']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #获取用户
        $user_info = $this->mUser->getUserInfo($user_id);

        #保存数据
        $aData = [
            'user_id'       =>  $user_id,
            'circle_id'     =>  $paramObj->circle_id,
            'avatar'        =>  $user_info->avatar,
        ];

        $supplier = $this->mCircle->GetCircleSupplierById($paramObj->circle_id);
        if($paramObj->is_like == 1)
        {
            DB::table('circle')->where('supplier_id',$supplier->supplier_id)->increment('like_num',1);
            $like_id = $this->mCircleLike->insert($aData);
            if($like_id)
                throw new Exception("用户点赞成功!", ErrorCodeEnum::STATUS_ERROR);
        }else{

            DB::table('circle')->where('supplier_id',$supplier->supplier_id)->increment('like_num',-1);
            $like = $this->mCircleLike->GetLikeById($paramObj->circle_id,$user_id);
            $result = $this->mCircleLike->delete(['like_id'=>$like->like_id]);
            if($result)
                throw new Exception("用户取消点赞成功!", ErrorCodeEnum::STATUS_ERROR);
        }


    }

    /**
     * 获取询价单列表
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-2-16
     */
    public function GetInquiryList($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['is_self']);
        if (!$check) {
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #登录验证
        if ($paramObj->is_self == 1 && !session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #获取询价单列表
        $inquiry_list = $this->mInquiry->GetInquiryList($paramObj->is_self,$paramObj->page,$user_id);

        $inquiry = [];
        foreach($inquiry_list as $k => $v)
        {
            #获取报价单列表
            $quote_num = $this->mCircleReply->GetInquiryNum($v->inquiry_id);
            $quote_list = $this->mCircleReply->GetInquiryList($v->inquiry_id);

            $inquiry['inquiry_list'][] = [
                    'inquiry_id'    =>  $v->inquiry_id,
                    'product_name'  =>  $v->product_name,
                    'spec'          =>  $v->spec,
                    'number'        =>  $v->number,
                    'supplier'      =>  $v->supplier,
                    'created'       =>  date('Y-m-d',$v->created),
                    'quote_num'     =>  $quote_num,
                    'inquiry_quote_list'    =>  $quote_list,
            ];

        }

        return $inquiry;
    }

    /**
     * 发布询价单
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author alice
     * @date 2016-1-26
     */
    public function PublishInquiry($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['product_name','spec','number','contact','mobile']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #手机号验证
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->mobile)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #保存数据
        $supplier   =   $this->mSupplier->GetSupplierNameById($user_id);

        $aData = [
            'supplier_id'   =>  $user_id,
            'supplier'      =>  $supplier->supplier_name,
            'product_name'  =>  $paramObj->product_name,
            'spec'          =>  $paramObj->spec,
            'number'        =>  $paramObj->number,
            'contact'       =>  $paramObj->contact,
            'mobile'        =>  $paramObj->mobile,
            'description'   =>  $paramObj->description,
            'created'       =>  time()
        ];
        return $this->mInquiry->insert($aData);

    }

    /**
     * 发布供货单
     * @param $paramObj
     * @return int
     * @throws Exception
     */
    public function PublishSupply($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['product_name','spec','price','stock','place','storage','contact','mobile']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #手机号验证
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->mobile)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #保存数据
        $supplier   =   $this->mSupplier->GetSupplierNameById($user_id);

        $aData = [
            'supplier_id'   =>  $user_id,
            'supplier'      =>  $supplier->supplier_name,
            'product_name'  =>  $paramObj->product_name,
            'spec'          =>  $paramObj->spec,
            'price'         =>  $paramObj->price,
            'stock'         =>  $paramObj->stock,
            'place'         =>  $paramObj->place,
            'storage'       =>  $paramObj->storage,
            'contact'       =>  $paramObj->contact,
            'mobile'        =>  $paramObj->mobile,
            'created'       =>  time()
        ];

        return $this->mSupply->insert($aData);
    }

    /**
     * 获取供货单成功
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-2-15
     */
    public function GetSupplyList($paramObj)
    {
        #登录验证
        if ($paramObj->is_self == 1 && !session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['is_self']);
        if (!$check) {
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #供货单信息
        $supply_info = $this->mSupply->GetSupplyList($paramObj->is_self,$paramObj->page,$user_id);

        $supply = [];
        foreach($supply_info as $k => $v)
        {
            #获取供货单回复数量
            $customize_num = $this->mCircleReply->GetSupplyNum($v->supply_id);

            #获取供货单回复列表
            $customize_list = $this->mCircleReply->GetSupplyInfo($v->supply_id);

            $supply['supply_list'][] = [
                'supply_id'             => $v->supply_id,
                'contact'               => $v->contact,
                'mobile'                => $v->mobile,
                'spec'                  => $v->spec,
                'number'                => $v->stock,
                'storage'               => $v->storage,
                'price'                 => $v->price,
                'created'               => date('Y-m-d',$v->created),
                'product_name'          => $v->product_name,
                'customize_num'         => $customize_num,
                'customize_list'        => $customize_list,
            ];
        }
        return $supply;


    }

    /**
     * 发布定制单
     * @param $paramObj
     * @return int
     * @throws Exception
     */
    public function PublishCustomize($paramObj)
    {
     /*   #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);*/

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['contact','mobile','description']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #手机号验证
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->mobile)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #保存数据
        $aData = [
            'contact'       =>  $paramObj->contact,
            'mobile'        =>  $paramObj->mobile,
            'description'   =>  $paramObj->description,
            'created'       =>  time()
        ];
        $arr = new stdClass();
        $arr->customize_id = $this->mCustomize->insert($aData);
        return $arr;
    }

    /**
     * 获取定制单
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author fyl
     * @date 2016-5-11
     */
    public function GetCustomizeList($paramObj)
    {
        #登录验证
        if ($paramObj->is_self == 1 && !session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['is_self']);
        if (!$check) {
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #供货单信息
        $CustomizeList = $this->mCustomize->GetCustomizeList($paramObj->is_self,$paramObj->page,$user_id);

        $customize = [];
        foreach($CustomizeList as $k => $v)
        {
            #获取报价单列表
            $quote_num  = $this->mCircleReply->GetCustomizeNum($v->customize_id);
            $quote_list = $this->mCircleReply->GetCustomizeInfo($v->customize_id);

            $customize['customize_list'][] = [
                'customize_id'                =>  $v->customize_id,
                'product_name'                =>  $v->product_name,
                'spec'                        =>  $v->spec,
                'number'                      =>  $v->number,
                'created'                     =>  date('Y-m-d',$v->created),
                'quote_num'                   =>  $quote_num,
                'customize_quote_list'        =>  $quote_list
            ];
        }

        return $customize;
    }

    /**
     * 消息中心
     * @param $paramObj
     * @return mixed
     * @throws Exception
     */
    public function GetNoticeList($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['is_read', 'page']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        return $this->mNotice->GetNoticeList($paramObj->is_read, $paramObj->page, $user_id);
    }

    /**
     * 获取消息内容
     * @param $paramObj
     * @return mixed
     * @throws Exception
     */
    public function GetNoticeDetail($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['notice_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #获取消息内容
        return $this->mNotice->GetNoticeDetail($paramObj->notice_id, $user_id);
    }

    /**
     * 头像上传
     * @param $paramObj
     * @return bool
     * @throws Exception
     */
    public function UploadAvatar($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['avatar']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #上传头像
        return $this->mUser->update(['avatar' => $paramObj->avatar],['user_id' => $user_id]);
    }

    /**
     * \删除消息
     * @param $paramObj
     * @return mixed
     * @throws Exception
     */
    public function DeleteNotice($paramObj)
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['notice_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #获取消息内容
        return $this->mNotice->DeleteNotice($paramObj->notice_id, $user_id);
    }

    /**
     * 回复木业圈需求单
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author alice
     * @date 2016-2-17
     */
    public function ReplyCircleRequest($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['reply_id','company','contact','mobile']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $aData = [
            'reply_id'  =>  $paramObj->reply_id,
            'company'   =>  $paramObj->company,
            'contact'   =>  $paramObj->contact,
            'mobile'    =>  $paramObj->mobile,
            'type'      =>  $paramObj->type,
            'price'     =>  $paramObj->price,
            'number'    =>  $paramObj->number,
            'user_id'   =>  $user_id,
            'created'   =>  time()
        ];

        return $this->mCircleReply->insert($aData);
    }

    /**
     * 订单列表
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author
     */
    public function OrderList($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
           throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #订单列表
        $order_list = $this->mOrder->GetOrderList($user_id,$paramObj->page);
        $orders = [];
        foreach ($order_list as $order)
        {
            #获取产品id
            $product_ids = $this->mOrderProduct->GetProductById($order->order_id);

            $product_list = [];
            foreach($product_ids as $product_id)
            {
                #获取产品列表
                $product_list = $this->mProduct->GetOrderProductList($product_id->product_id,$user_id);
            }

            $orders['order_list'][] = [
                'order_id'          =>  $order->order_id,
                'order_sn'          =>  $order->order_sn,
                'order_time'        =>  date('Y-m-d H:i',$order->order_time),
                'log_status'        =>  $order->log_status,
                'amount'            =>  $order->amount,
                'order_status'      =>  $order->order_status,
                'product_list'      =>  $product_list,
            ];
        }

        return $orders;

    }

    /**
     * 订单详情
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-2-18
     */
    public function OrderDetail($paramObj)
    {
        #登录验证
//        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
//            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
//          $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['order_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #订单详情
        $order_info = $this->mOrder->GetOrderDetail($paramObj->order_id);

        #产品列表
        $order_product = $this->mProduct->GetOrderProductList1($order_info->product_id,$paramObj->order_id);

        #地址列表
        $order_adress =  $this->mAddress->GetOrderAddress($order_info->address_id);

        if($order_info->pay_time==0){
           $pay_time = 0;
        }else{
           $pay_time = date('Y-m-d H:i:s',$order_info->pay_time);
        }
        if($order_info->send_time==0){
            $send_time = 0;
        }else{
            $send_time = date('Y-m-d H:i:s',$order_info->send_time);
        }
        if($order_info->deal_time==0){
            $deal_time = 0;
        }else{
            $deal_time = date('Y-m-d H:i:s',$order_info->deal_time);
        }
        return [
            "order_id"          =>$order_info->order_id,
            "order_sn"          =>$order_info->order_sn,
            "order_time"        =>date('Y-m-d H:i:s',$order_info->order_time),
            "order_status"        =>$order_info->order_status,
            "trade_num"        =>$order_info->trade_num,
            "amount"           =>$order_info->amount,
            "pay_time"          =>$pay_time,
            "send_time"         =>$send_time,
            "deal_time"             =>$deal_time,
            "product_id"        =>$order_info->product_id,
           // "number"            =>$order_info->number,
            "supplier_name"    =>$order_info->supplier_name,
            "phone"    =>$order_info->phone,
            "user_name"        =>$order_info->user_name,
            'product_list'    =>  $order_product,
            'order_adress'    =>  $order_adress,
        ];
    }

    /**
     * 订单状态
     * @param $paramObj
     * @return array
     * @throws Exception
     */
    public function OrderStatus($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        //$user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['order_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #订单详情
        $order_info = $this->mOrder->GetOrderDetail($paramObj->order_id);

        #状态列表
        $status = $this->mLogisticsStatus->GetOrderStatus($paramObj->order_id);
        if(!empty($status)){
            foreach($status as &$s){
                $s->update_time = date('Y-m-d H:i:s');
            }
        }


        return [
            "order_id"          => $order_info->order_id,
//            "order_sn"          =>$order_info->order_sn,
//           "order_sn"         => $this->make_order($user_id),
            "status"            => $status
        ];
    }

    public function make_order($user_id)
    {
        return 'MT'.mt_rand(10,99)
        . sprintf('%010d',time() - 946656000)
        . sprintf('%03d', (float) microtime() * 1000)
        . sprintf('%03d', (int) $user_id % 1000);
    }

    /**
     * 确认订单
     * @return array
     * @throws Exception
     * @author fyl
     * @date 2016-5-10
     */
    public function ConfirmOrder($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #默认收货地址
        $address = $this->mAddress->GetAddressDefault($user_id);

        #获取购买产品列表
        $products = $this->mCart->GetCartProducts($user_id,$paramObj->cart_id);
        $products->amount = number_format($products->number*$products->price,2);
      /*  #支付
        $pay_mode = $this->mPayMode->GetPayModeDefault();
       */
       /* #配送
        $shipping = $this->mShipping->GetShippingDefault();*/

     /*   #发票类型
        $invoice = $this->mInvoice->GetShippingDefault();*/

        $order                      =   new stdClass();
        $order->default_address     =   $address;
        $order->products            =   $products;
    /*    $order->pay_mode            =   $pay_mode;
        $order->shipping            =   $shipping;
        $order->invoice             =   $invoice;*/

        return $order;
    }


    /**
     * 获取发票类型
     * @return array
     */
    public function GetInvoiceList()
    {
        $this->mInvoice->setSelect(['invoice_id','invoice_type']);
        return $this->mInvoice->fetchAll([],[],['invoice_id' => 'asc']);
    }

    /**
     * 订单生成
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author fyl
     * @date 2016-5-12
     */
    public function GenerateOrder($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['address_id','cart_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #获取购物车信息
        $cart_info  =   $this->mCart->GetCartProducts($user_id,$paramObj->cart_id);
        #开始事务
        DB::beginTransaction();
        try{
            $order_sn       =   ToolKit::make_order_sn();
            $order_data = [
                    'user_id'            => $user_id,                                //用户ID
                    'supplier_id'        => $cart_info->supplier_id,                 //商家ID
                    'address_id'         => $paramObj->address_id,                   //收货地址id
                    'order_time'         => time(),                                  //订单生成时间
                    'order_sn'           => $order_sn,                               //订单号
                    'confirm_time'       => time(),                                  //确认订单时间
                    'order_status'       => OrderEnum::STATUS_NO_PAY,                //订单状态
                    'start_amount'       => $cart_info->number*$cart_info->price,    //初始总价
                    'amount'             => $cart_info->number*$cart_info->price,    //订单总价
                    'trade_num'          => 'MTW'.time().rand(100,999),                   //交易流水号
                ];
                $order_id               =   $this->mOrder->insert($order_data);
                if(!$order_id)
                    throw new Exception('订单创建失败！', ErrorCodeEnum::STATUS_ERROR);
                    $aData = [
                        'product_id'    =>  $cart_info->product_id,
                        'supplier_id'   =>  $cart_info->supplier_id,
                        'order_id'      =>  $order_id,
                        'price'         =>  empty($cart_info->price)?'':$cart_info->price,
                        'number'        =>   empty($cart_info->number)?'':$cart_info->number,
                    ];
                    $order_product = $this->mOrderProduct->insert($aData);
                    #减库存
                    $stock = DB::table('product')
                        ->where('product_id',$cart_info->product_id)
                        ->where('stock',">=",$cart_info->number)
                        ->decrement('stock',$cart_info->number);
                   $sales =  DB::table('product')
                       ->where('product_id',$cart_info->product_id)
                       ->increment('sales', $cart_info->number);
                    if(!$order_product || !$sales)
                        throw new Exception('订单创建失败！', ErrorCodeEnum::STATUS_ERROR);
                    if( !$stock )
                        throw new Exception('库存不足！', ErrorCodeEnum::STATUS_ERROR);
            #结束事务
            DB::commit();
            #清空购物车
          $this->mCart->delete(['cart_id' => $paramObj->cart_id]);
            $arr = new stdClass();
            $arr->order_id = $order_id;
            return $arr;
        } catch(Exception $e){
            #事务回滚
            DB::rollback();
            throw $e;
        }

    }

    /**
     * 发送反馈
     * @param $paramObj
     * @return int
     * @throws Exception
     * @author alice
     * @date 2016-2-18
     */
    public function SendFeedback($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['content']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);


        #存储数据
        $aData = [
            'user_id'        => $user_id,
            'content'        => $paramObj->content,
            'mobile'         => $paramObj->mobile,
            'created'        => time()
        ];

        return $this->mFeedback->insert($aData);
    }

    /**
     * 反馈列表
     * @param $paramObj
     * @return stdClass
     * @date 2016-03-03
     * @author buluota
     */
    public function GetFeedbackList($paramObj)
    {
        $feedback                   = new stdClass();
        $feedback->feedback_list    = $this->mFeedback->GetFeedbackList($paramObj->page);

        return $feedback;
    }

    /**
     * 买（卖）家全部订单（待付款，待收货，已完成）
     * @author liuyuchao
     * @data 2016-05-07
     */
    public function GetOrderAll($user_id,$supplier_id,$status,$page)
    {

        if ($user_id=="" || $status=="" || $supplier_id=="")
            throw new Exception('参数不能为空', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        return $this->mOrder->OrderSelect($user_id,$supplier_id,$status,$page);

    }
    /**
     * 取消订单
     * @param $paramObj
     * @return mixed
     * @throws Exception
     */

    public function CancelOrder($order_id)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
        throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
//        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
      if($order_id==0 || $order_id=="") {
          throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
      }
        return $this->mOrder->CancelOrder($order_id);
    }

    /**
     * 确认收货
     * @param $order_id
     * @return mixed
     * @throws Exception
     */

    public function ConfirmReceipt($order_id)
    {
        #登录验证
           if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
           throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
//         $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        if($order_id==0 || $order_id=="") {
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        return $this->mOrder->ConfirmReceipt($order_id);
    }
    /**
     * 修改价格
     * @param $order_id
     * @param $amount
     * @return mixed
     * @throws Exception
     */

    public function ChangePrice($order_id,$amount)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
        throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
//        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        if($order_id==0 || $order_id=="") {
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        return $this->mOrder->ChangePrice($order_id,$amount);
    }
    /**
     * 确认发货
     * @param $order_id
     * @return mixed
     * @throws Exception
     */

    public function SendGoods($order_id)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
        throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
       // $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        if($order_id==0 || $order_id=="") {
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        return $this->mOrder->SendGoods($order_id);
    }
    /**
     * 删除订单
     * @param $order_id
     * @return mixed
     * @throws Exception
     */
    public function DeleteOrder($order_id)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
//        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($order_id);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        return $this->mOrder->DeleteOrder($order_id);
    }

    /**
     * 支付配送
     * @return array
     */
    public function PayShipping()
    {
        #支付列表
        $pay_list = $this->mPayMode->GetPayModeList();

        #配送列表
        $shipping = $this->mShipping->GetShippingList();

        return [
            'pay_list'      => $pay_list,
            'shipping_list' => $shipping
        ];
    }

    //删除库存商品
    public function DeleteStoreProduct($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check      =   $this->checkProperties($paramObj, ['product_id']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        #逻辑处理
        return $this->mProduct->DeleteStoreProduct($paramObj->product_id, $user_id);
    }

    /**
     * 添加产品
     * @param $paramObj
     * @return bool
     * @throws Exception
     * @date 2016-03-02
     * @author buluota
     */
    public function AddProduct($paramObj)
    {
        #登录验证
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check  = $this->checkProperties($paramObj,  ['product_name','category','spec','stock','price']);
        if (!$check)
            throw new Exception('参数不足', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        $data = [
            'product_name'  => $paramObj->product_name,
            'category'      => $paramObj->category,
            'classes'       => empty($paramObj->classes)?'':$paramObj->classes,
            'spec'          => $paramObj->spec,
            'place'         => empty($paramObj->place)?'':$paramObj->place,
            'storage'       => empty($paramObj->storage)?'':$paramObj->storage,
            'stock'         => $paramObj->stock,
            'start_num'     => empty($paramObj->start_num)?'':$paramObj->start_num,
            'product_img'   => empty($paramObj->product_img)?'':$paramObj->product_img,
            'description'   => empty($paramObj->description)?'':$paramObj->description,
            'price'         => $paramObj->price,
            'supplier_id'   => $user_id,
            'created'       => time(),
            'contact'       =>  empty($paramObj->contact)?'':$paramObj->contact,
            'contact_name'  =>  empty($paramObj->contact_name)?'':$paramObj->contact_name,
        ];

        if($paramObj->product_id){
            $data['status'] = 2;
            $product_id = $this->mProduct->update($data,['product_id' => $paramObj->product_id]);
        }else{
            $data['product_sn']   = ToolKit::make_product_sn();
            $product_id = $this->mProduct->insert($data);
        }
        if(!$product_id)
            throw new Exception('添加产品失败!', ErrorCodeEnum::STATUS_ERROR);

        #插入产品媒体库
        $aData = [
                    'product_id' => empty($paramObj->product_id) ?$product_id: $paramObj->product_id,
                    'show_img2' => empty($paramObj->show_img1) ?'' : $paramObj->show_img1,
                    'show_img3' => empty($paramObj->show_img2) ? '' : $paramObj->show_img2,
                    'show_img1' => empty($paramObj->product_img) ? '' : $paramObj->product_img
        ];

        if($paramObj->product_id){
            $product_pic = $this->mProductPic->update($aData,['product_id' => $paramObj->product_id]);
        }else{
            $product_pic = $this->mProductPic->insert($aData);
        }

        if(!$product_pic)
            throw new Exception('添加/修改产品失败!', ErrorCodeEnum::STATUS_ERROR);
        $pro = new stdClass();
        $pro->status = $product_id && $product_pic;
        return $pro;
    }

    /**
     * 产品分类信息
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-2-24
     */
    public function GetCategories()
    {
        #获取分类
        $Category = $this->mProductCate->GetProductCategory();
        $category = [];
        foreach ($Category as $cate) {
            #获取品类
            $classes = $this->mProductCate->GetProductClasses($cate->cate_id);
            $classes_list = [];
            foreach ($classes as $v){
                #获取材质
                $quality = $this->mProductCate->GetProductQuality($v->cate_id);
                $quality_list = [];
              foreach ($quality as $q) {
                  /*    #获取规格
                    $spec = $this->mSpec->GetSpecList($q->cate_id);

                    #获取等级
                    $level = $this->mLevel->GetLevelList($q->cate_id);
*/
                    $quality_list[] = [
                        'id'    => $q->cate_id,
                        'name'  => $q->cate_name,
                      /*  'spec'  => $spec,
                        'level' => $level,*/
                    ];
                }
                $classes_list[] = [
                    'id'         => $v->cate_id,
                    'name'       => $v->cate_name,
                    'quality'    => $quality_list
                ];
            }

            $category[] = [
                'id' => $cate->cate_id,
                'name' => $cate->cate_name,
                'classes' => $classes_list
            ];
        }

   /*     #产地
        $place = $this->mPlace->GetPlaceList();

        #品牌
        $brands = $this->mProductBrand->GetBrandList();

        #仓储地
        $storage = $this->mStorage->GetProductStorageList();*/
        return [
            'category'  =>  $category,
         /*   'brands'    =>  $brands,
            'storage'   =>  $storage,
            'place'     =>  $place,*/
        ];


    }

    public function VideoPlayUrl($paramObj)
    {
        #视频url
        $result = $this->mVideo->VideoPlayUrl($paramObj->type_id, $paramObj->video_id);
        if(!$result){
            throw new Exception("获取url地址失败!", ErrorCodeEnum::STATUS_ERROR);
        }

        return $result;
    }
    //更改订单状态
    public function UpdateStatus($TradeNmm){
        return $this->mOrder->updatestatus($TradeNmm);

    }
    //支付失败更改流水号
    public function UpdateTradeNum($TradeNmm){
        return $this->mOrder->UpdateTradeNum($TradeNmm);

    }
    //搜索订单字段提交给支付
    public function SelectOrder($order_id){
        $order_info = $this->mOrder->SelectOrder($order_id);
        return [
            "order_id"          =>$order_info->order_id,
            "order_sn"          =>$order_info->order_sn,
            "order_time"        =>$order_info->order_time,
            "amount"        =>$order_info->amount,
            "trade_num"        =>$order_info->trade_num,
            ];

    }
    //查询状态
    public function SelectOrderStatus($tradeNum){
        $order_info = $this->mOrder->OrderStatus($tradeNum);
        return [
            "order_status"          =>$order_info->order_status,
        ];

    }
    //意见反馈
    public function Opinion($content,$phone){
        $aDate = [
            'opinion_content'        => $content,
            'phone'       => $phone

        ];
        return $this->mOpinoin->Opinion($aDate);

    }
//pos机
    public function poslogin($data){
        $obj=json_decode($data);
        $TerminalNo = $obj->TerminalNo;//设备号
        $LoginName = $obj->LoginName;//工号
        $Password = $obj->Password;//密码
        $user_info = $this->mPosUser->poslogin($TerminalNo, $LoginName,$Password);
        if (!$user_info) {
            throw new Exception("用户名或密码错误", ProfessionErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
        }
        return $user_info;
    }

    //登出
    public function posloginout($data){
        $obj=json_decode($data);
        $TerminalNo=$obj->TerminalNo;
        $LoginName=$obj->LoginName;

        $user_info = $this->mPosUser->posloginout($TerminalNo, $LoginName);
        if($user_info == 1){

              return "{\"Response\":\"00\",\"Message\":\"\"}";
        }else{

             return "{\"Response\":\"01\",\"Message\":\"\"}";
        }
    }


    //获取订单信息
    public function posgetOrder($data){
        $obj=json_decode($data);

        $LoginName=$obj->LoginName;
        $BarCode=$obj->BarCode;

        //Todo:实现自己的业务逻辑

        //return   "{\"Response\":\"00\",\"Message\":\"\",\"BarCode\":\"".$BarCode."\",\"EnterpriseID\":\"002\",\"Commoditys\":[],\"OrderNumber\":\"\",\"RecipientCode\":\" \",\"RecipientName\":\"王云\",\"RecipientAddress\":\"吉林省长春市经济技术开发区东环城路与安乐路交汇东方之珠北区31栋四单元507\",\"RecipientPhone\":\"1776554****\",\"Payment\":0.01,\"Weight\":0.547,\"Postage\":0,\"ServiceCharge\":0,\"PostagePostPaidFlag\":1,\"MailType\":1,\"Description\":\"送货时间不限\"}";
    }

    //得到报告结果
    public function posreport($data){

        $obj=json_decode($data);
        //echo $data;
        $TerminalNo=$obj->TerminalNo;
        $LoginName=$obj->LoginName;
        $BarCode=$obj->BarCode;
        $CardNo=$obj->CardNo;
        $CardType=$obj->CardType;
        $BusinessTime=$obj->BusinessTime;
        $TerminalDealID=$obj->TerminalDealID;
        $UnionpayDealID=$obj->UnionpayDealID;
        $TotalPayment=$obj->TotalPayment;
        $AccountReceived=$obj->AccountReceived;
        $State=$obj->State;
        $UntreadReasonCode=$obj->UntreadReasonCode;
        $Description=$obj->Description;

        $Message="";
        switch($State){
            case "00":
                $Message="刷卡";
                break;
            case "30":
                $Message="现金成功";
                break;
            case "20":
                $Message="拒收";
                break;
            case "40":
                $Message="异常(问题件)";
                break;
            case "70":
                $Message="运单交易撤销成功";
                break;
        }
       // return "{\"Response\":\"00\",\"Message\":\"".$Message."\"}";
    }

    public function posgetOrderlist($data){

        $obj=json_decode($data);
        $TerminalNo=$obj->TerminalNo;
        $LoginName=$obj->LoginName;
        $RetCount=$obj->RetCount;

        //Todo:实现自己的业务逻辑

    //    return "{\"Response\":\"00\",\"Message\":\"\",\"Data\":[{\"OrderNumber\":\"1000333123\",\"Payment\":89},{\"OrderNumber\":\"1000333126\",\"Payment\":8}]}";

    }

}